<!--
 @description  选择方案
 @fileName AddProgramme.vue
 @author zengqiongying
 @created 2024/08/19 09:15:30
-->
<template>
  <el-dialog
    ref="refDlg"
    v-el-drag-dialog
    width="700px"
    title="选择方案"
    :visible.sync="dialogShow"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    class="dialog-content-no-padding-top"
    @close="closeDialog"
  >
    <table-box
      ref="refTable"
      :table-config="tableConfig"
      :other-filters="otherFilters"
      :table-height="400"
      :selected-arry.sync="tableSelected"
      :show-custom-setting="false"
      :show-custom-combine="false"
      :table-sortable="false"
      @row-dblclick="dbClickRow"
    >
      <!-- <el-table-column v-if="multiple" slot="before" type="selection" reserve-selection width="40" /> -->
    </table-box>

    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="closeDialog">取 消</el-button>
      <el-button type="primary" size="mini" @click="handleSure">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'AddProgramme',
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      otherFilters: [
        // { id: 'state', property: 'state', operator: '=', value: 1 }
      ],
      paramsRaw: {},
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/scheme/2.0/search`,
        onlySearchBar: true,
        tabIndex: 21,
        setting: [
          {
            prop: 'programmeName',
            label: '方案名称'
          },
          {
            prop: 'createBy',
            label: '上传用户',
            minWidth: 150
          },
          {
            prop: 'createTime',
            label: '上传时间',
            minWidth: 150
          }
        ]
      },
      tableSelected: [] // 单选行

    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },

  created() {},
  activated() {},

  mounted() {},

  methods: {
    closeDialog() {
      this.tableSelected = []
      this.dialogShow = false
    },
    handleClick() {

    },
    // 刷新表格数据
    refreshTable(isInit) {
      this.$nextTick(() => {
        this.$refs.refTable.initTableData(isInit ? '' : 'onPage')
      })
    },
    dbClickRow(row, e) {
      this.tableSelected = [row]
      this.handleSure()
    },
    handleSure() {
      if (this.tableSelected.length === 0) {
        this.$message.warning('请先选择方案')
        return
      }
      this.$emit('change', this.tableSelected[0])
      this.closeDialog()
    }
  }
}

</script>
<style lang='scss' scoped>

</style>
